{template '_header'}

<link href="../addons/ewei_shopv2/plugin/diypage/static/css/template.css?v=201606141600" rel="stylesheet" type="text/css"/>

<form action="./index.php" method="get">
	<input type="hidden" name="c" value="site">
	<input type="hidden" name="a" value="entry">
	<input type="hidden" name="m" value="ewei_shopv2">
	<input type="hidden" name="do" value="web">
	<input type="hidden" name="r" value="diypage.temp">
	<input type="hidden" name="type" value="{$_GPC['type']}">
	<input type="hidden" name="cate" value="{$_GPC['cate']}">
	<div class="page-heading">
		<span class="pull-right input-group" style="width: 200px">
			<input type="text" class="input-sm form-control" name="keyword" value="{$_GPC['keyword']}" placeholder="请输入模板名称">
			<span class="input-group-btn">
				<button class="btn btn-sm btn-primary" type="submit" style="margin-left: 0; border-radius: 0"> 搜索</button>
			</span>
		</span>
		<h2><i class="fa fa-circle-o"></i>模板管理 <small>总数({$total})</small></h2>
	</div>
</form>

<div class="form-horizontal">
	<div class="form-group">
		<div class="col-sm-2 control-label" style="width: 75px; font-size: 14px; padding: 0;">模板类型</div>
		<div class="col-sm-10">
			<a class="btn btn-xs {if $_GPC['type']==''}btn-info{else}btn-default{/if}" href="{php echo webUrl('diypage/temp', array('type'=>'', 'cate'=>$_GPC['cate'], 'keyword'=>$_GPC['keyword']))}">全部类型</a>
			<a class="btn btn-xs {if $_GPC['type']==1}btn-info{else}btn-default{/if}" href="{php echo webUrl('diypage/temp', array('type'=>1, 'cate'=>$_GPC['cate'], 'keyword'=>$_GPC['keyword']))}">自定义页面</a>
			<a class="btn btn-xs {if $_GPC['type']==2}btn-info{else}btn-default{/if}" href="{php echo webUrl('diypage/temp', array('type'=>2, 'cate'=>$_GPC['cate'], 'keyword'=>$_GPC['keyword']))}">商城首页</a>
			{if $_W['plugin']!='merch'&&empty($_W['merchid'])}
				<a class="btn btn-xs {if $_GPC['type']==3}btn-info{else}btn-default{/if}" href="{php echo webUrl('diypage/temp', array('type'=>3, 'cate'=>$_GPC['cate'], 'keyword'=>$_GPC['keyword']))}">会员中心</a>
				{if p('commission')}
				<a class="btn btn-xs {if $_GPC['type']==4}btn-info{else}btn-default{/if}" href="{php echo webUrl('diypage/temp', array('type'=>4, 'cate'=>$_GPC['cate'], 'keyword'=>$_GPC['keyword']))}">分销中心</a>
				{/if}
				<a class="btn btn-xs {if $_GPC['type']==5}btn-info{else}btn-default{/if}" href="{php echo webUrl('diypage/temp', array('type'=>5, 'cate'=>$_GPC['cate'], 'keyword'=>$_GPC['keyword']))}">商品详情</a>
				{if p('creditshop')}
				<a class="btn btn-xs {if $_GPC['type']==6}btn-info{else}btn-default{/if}" href="{php echo webUrl('diypage/temp', array('type'=>6, 'cate'=>$_GPC['cate'], 'keyword'=>$_GPC['keyword']))}">积分商城</a>
				{/if}
				{if p('seckill')}
				<a class="btn btn-xs {if $_GPC['type']==7}btn-info{else}btn-default{/if}" href="{php echo webUrl('diypage/temp', array('type'=>7, 'cate'=>$_GPC['cate'], 'keyword'=>$_GPC['keyword']))}">整点秒杀</a>
				{/if}
				{if p('exchange')}
				<a class="btn btn-xs {if $_GPC['type']==8}btn-info{else}btn-default{/if}" href="{php echo webUrl('diypage/temp', array('type'=>8, 'cate'=>$_GPC['cate'], 'keyword'=>$_GPC['keyword']))}">兑换中心</a>
				{/if}
			{/if}
		</div>
	</div>
	<div class="form-group">
		<div class="col-sm-2 control-label" style="width: 75px; font-size: 14px; padding: 0;">模板分类</div>
		<div class="col-sm-10">
			<a class="btn btn-xs {if $_GPC['cate']==''}btn-info{else}btn-default{/if}" href="{php echo webUrl('diypage/temp', array('cate'=>'', 'type'=>$_GPC['type'], 'keyword'=>$_GPC['keyword']))}">全部分类</a>
			<a class="btn btn-xs {if $_GPC['cate']=='0'}btn-info{else}btn-default{/if}" href="{php echo webUrl('diypage/temp', array('cate'=>'0', 'type'=>$_GPC['type'], 'keyword'=>$_GPC['keyword']))}">未分类</a>
			{loop $category $item}
			<a class="btn btn-xs {if $_GPC['cate']==$item['id']}btn-info{else}btn-default{/if}" href="{php echo webUrl('diypage/temp', array('cate'=>$item['id'], 'type'=>$_GPC['type'], 'keyword'=>$_GPC['keyword']))}">{$item['name']}</a>
			{/loop}
		</div>
	</div>
</div>

<div class="row">
	{if empty($list)}
		<div class="panel panel-default" style="margin: 0 15px;">
			<div class="panel-body" style="text-align: center; padding:30px 0;">
				未查询到模板!
			</div>
		</div>
	{else}
		{loop $list $item}
			<div class="item">
				<img src="{php echo tomedia($item['preview'])}" onerror="this.src='../addons/ewei_shopv2/plugin/diypage/static/images/nopic.jpg'" />
				<div class="cate">
					{if $item['uniacid']==0}
						<span class="label label-primary">系统</span>
					{/if}
					<span class="label label-{$allpagetype[$item['type']]['class']}">{$allpagetype[$item['type']]['name']}</span>
				</div>
				<div class="title">{if !empty($item['name'])}{$item['name']}{else}未命名{/if}</div>
				<div class="mask">
					<div class="btns">
						<a class="btn btn-primary btn-block btn-sm create" data-href="{php echo webUrl('diypage/page')}.{$allpagetype[$item['type']]['pagetype']}.add&tid={$item['id']}&type={$item['type']}">创建页面</a>
						{if empty($item['uniacid'])}
							{if $_W['isfounder']}
								<a class="btn btn-default btn-block btn-sm delete" data-tid="{$item['id']}">删除模板</a>
							{/if}
						{else}
							{ifp 'diypage.temp.delete'}
								<a class="btn btn-default btn-block btn-sm delete" data-tid="{$item['id']}">删除模板</a>
							{/if}
						{/if}
					</div>
				</div>
			</div>
		{/loop}
	{/if}
</div>
{$pager}

<script>
	$(".item").hover(function () {
		$(this).find('.mask').stop().fadeIn();
		$(this).find('.title').stop().fadeIn();
	}, function () {
		$(this).find('.mask').stop().fadeOut();
		$(this).find('.title').stop().fadeOut();
	});
	$(".create").unbind('click').click(function () {
		var href = $(this).data('href');
		if(!href) {
			tip.confirm("创建失败，模板参数错误！");
			return;
		}
		location.href = href;
	});
	$(".delete").unbind('click').click(function () {
		var _this = $(this);
		var status = _this.data('status');
		var tid = _this.data('tid');
		if(status) {
			tip.msgbox.err("正在删除中，请稍候。");
		}
		if(!tid){
			tip.msgbox.err("模板参数错误，请刷新重试！");
			return;
		}
		tip.confirm("删除后不可恢复，确定创建此模板？", function () {
			_this.data('status',1).text('删除中..');
			$.post("{php echo webUrl('diypage/temp/delete')}", {id: tid,}, function (r) {
				if (r.status==0) {
					tip.msgbox.suc("删除成功！");
					_this.closest('.item').fadeOut().remove();
					setTimeout(function () {
						location.reload();
					}, 500);
				} else {
					tip.msgbox.err(r.result.message);
					_this.data('status',0).text('删除模板');
				}
			}, 'json');
		});
	});
</script>

{template '_footer'}